<?
################################################################################
##              -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =-                 #
## --------------------------------------------------------------------------- #
##  PHP DataGrid version 4.2.8 (01.10.2008)                                    #
##  Author & developer:     Leumas Naypoka <leumas.a@gmail.com>                #
##  Developers:             Zewa           <http://www.softic.at>              #
##                          Fcallez        <http://www.innovavirtual.org>      #
##  Lisence:    GNU GPL                                                        #
##  Site:       http://phpbuilder.blogspot.com                                 #
##  Copyright:  Leumas Naypoka (c) 2006-2008. All rights reserved.             #
################################################################################

//require_once "../funciones.php";
//session_start();
//$con = con_intranetpccom();
  define ("DATAGRID_DIR", "../datagrid/");                     /* Ex.: "datagrid/" */
  define ("PEAR_DIR", "../datagrid/pear/");                    /* Ex.: "datagrid/pear/" */

  require_once(DATAGRID_DIR.'datagrid.class.php');
  require_once(PEAR_DIR.'PEAR.php');
  require_once(PEAR_DIR.'DB.php');

//Parametros del Sistema
$sistema = $_REQUEST['sistema'];
$reqId  = $_REQUEST['reqId'];
$empresa = $_REQUEST['empresa'];
$responsable = $_REQUEST['responsable'];
$estado = $_REQUEST['estado'];
$tipo   = $_REQUEST['tipo'];
$estResp = $_REQUEST['estResp'];
$fecIni = $_REQUEST['fecIni'];
$fecFin = $_REQUEST['fecFin'];

//Valido los valores, si vienen vacios se manipulan para hacer la consulta
if ($fecIni == "")
    $fecIni = "1800-01-01";
if ($fecFin == "")
    $fecFin = "2888-12-31";
$fecFin .= " 23:59:59";

$where = " where req.reqFec between '$fecIni' and '$fecFin' ";
$where .= ($responsable != "")? " and sol.solRqUsr = '$responsable' " : "";
$where .= ($estado != "")? " and sol.estRqId = $estado " : "";
$where .= ($tipo != "")? " and sol.tipRqId = $tipo " : "";
$where .= ($opc == 1)? " and sol.solRqId in (select max(reqAux.solRqId) from solucionesRq reqAux where reqAux.reqId = req.reqId) " : "";
$where .= ($reqId != "")? " and req.reqId = $reqId " : "";
$where .= ($empresa != "")? " and emp.empresa = '$empresa' " : "";
$where .= ($sistema != "")? " and sis.sisId = '$sistema' " : "";
$where .= ($estResp == "pendientes" )? " and sol.estRqId <> 3 " : " and sol.estRqId = 3 ";


##  *** creating variables that we need for database connection
  $DB_USER='caweb';
  $DB_PASS='caweb';
  $DB_HOST='localhost';
  $DB_NAME='intranetpccom';

  ob_start();

  $db_conn = DB::factory('mysql');  /* don't forget to change on appropriate db type */
  $result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
  if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); }
##  *** put a primary key on the first place
  $sql = "select req.reqId as rq from requerimientos as req
            left join solucionesRq sol on sol.reqId = req.reqId
            where sol.solRqId in (select max(reqAux.solRqId) from solucionesRq as reqAux where reqAux.reqId = req.reqId)

";
 //where sol.solRqId in (select max(reqAux.solRqId) from solucionesRq as reqAux where reqAux.reqId = req.reqId) ";
//    $sql = "select distinct (req.reqId) as rq, req.reqFec,concat(usr.nombres,' ',usr.apellidos) as reqUsr,emp.texto4,req.reqDes, sis.sisNombre,req.reqArc as archivo from requerimientos req
//            left join solucionesRq sol on sol.reqId = req.reqId
//            inner join usuarios usr on usr.username = req.reqUsr
//            inner join empresas emp on emp.empresa = usr.entrada
//            inner join sistemas sis on sis.sisId = req.sisId " . $where;
##  *** set needed options and create a new class instance
  $debug_mode = true;        /* display SQL statements while processing */
  $messaging = true;          /* display system messages on a screen */
  $unique_prefix = "f_";      /* prevent overlays - must be started with a letter */
  $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);
##  *** set data source with needed options
  $default_order_field = "rq,sol.solRqId";
  $default_order_type = "ASC,DESC";
  $dgrid->dataSource($db_conn, $sql, $default_order_field, $default_order_type);

##  *** set encoding and collation (default: utf8/utf8_unicode_ci)
 $dg_encoding = "utf8";
 $dg_collation = "utf8_unicode_ci";
 $dgrid->setEncoding($dg_encoding, $dg_collation);
##  *** set interface language (default - English)
 $dg_language = "es";
 $dgrid->setInterfaceLang($dg_language);
##  *** set direction: "ltr" or "rtr" (default - "ltr")
 $direction = "ltr";
 $dgrid->setDirection($direction);
##  *** set layouts: 0 - tabular(horizontal) - default, 1 - columnar(vertical)
 $layouts = array("view"=>0, "edit"=>0, "filter"=>1);
 $dgrid->setLayouts($layouts);
##  *** set modes for operations ("type" => "link|button|image")
##  *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
 $modes = array(
    "add"	 =>array("view"=>false, "edit"=>false, "type"=>"link"),
    "edit"	 =>array("view"=>false, "edit"=>false,  "type"=>"link", "byFieldValue"=>""),
    "cancel"  =>array("view"=>true, "edit"=>true,  "type"=>"link"),
    "details" =>array("view"=>false, "edit"=>false, "type"=>"link"),
    "delete"  =>array("view"=>false, "edit"=>false,  "type"=>"image")
 );
 $dgrid->setModes($modes);

##  *** allow scrolling on datagrid

$scrolling_option = false;
$dgrid->allowScrollingSettings($scrolling_option);
##  *** set scrolling settings (optional)

$scrolling_width = "100%";
$scrolling_height = "100%";
$dgrid->setScrollingSettings($scrolling_width, $scrolling_height);

##  *** allow mulirow operations
 $multirow_option = false;
 $dgrid->allowMultirowOperations($multirow_option);
 $multirow_operations = array(
    "delete"  => array("view"=>false),
    "details" => array("view"=>false)
 );
 $dgrid->setMultirowOperations($multirow_operations);
 $css_class = "blue";
 $css_type = "embedded";
 $dgrid->setCssClass($css_class, $css_type);
 $anotherDatagrids = array("fp_"=>array("view"=>false, "edit"=>true, "details"=>true));
 $dgrid->setAnotherDatagrids($anotherDatagrids);

 $dg_caption = "";
 $dgrid->setCaption($dg_caption);


 $printing_option = false;
 $dgrid->allowPrinting($printing_option);
 $exporting_option = false;
 $dgrid->allowExporting($exporting_option);

 $sorting_option = true;
 $dgrid->allowSorting($sorting_option);
##  *** set paging option: true(default) or false
 $paging_option = true;
 $rows_numeration = false;
 $numeration_sign = "N #";
 $dgrid->allowPaging($paging_option, $rows_numeration, $numeration_sign);
##  *** set paging settings
 $bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
 $top_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
 $pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
 $default_page_size = 10;
 $paging_arrows = array("first"=>"|&lt;&lt;", "previous"=>"&lt;&lt;", "next"=>"&gt;&gt;", "last"=>"&gt;&gt;|");
 $dgrid->setPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size, $paging_arrows);

 $filtering_option = false;
 $dgrid->allowFiltering($filtering_option);

 $vm_colimns = array(
  "rq"          =>array("header"=>"Inc",        "type"=>"link", "align"=>"center", "width"=>"80px", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "field_key"=>"rq", "field_data"=>"rq", "rel"=>"", "title"=>"", "target"=>"", "href"=>"javascript: llamaModal({0})"),
  //"reqFec"      =>array("header"=>"Fecha",      "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
  //"reqUsr"      =>array("header"=>"Usuario",    "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
  //"texto4"      =>array("header"=>"Empresa",    "type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
  //"reqDes"      =>array("header"=>"Descripcion","type"=>"label", "width"=>"10px","align"=>"left", "wrap"=>"wrap", "text_length"=>"-1", "case"=>"normal"),
  //"archivo"     =>array("header"=>"Archivo Relacion", "type"=>"link", "align"=>"center", "width"=>"80px", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "field_key"=>"archivo", "field_data"=>"archivo", "rel"=>"", "title"=>"", "target"=>"", "href"=>"../requerimientos/{0}"),
  );
  $dgrid->setColumnsInViewMode($vm_colimns);

?>

<html>
<head>
        <title></title>
        <meta http-equiv=Content-Type content="text/html; charset=UTF-8">
        <script src="../js/jquery.js" type="text/javascript"></script>
        <script src='../js/thickbox-compressed.js' type='text/javascript'></script>
        <link rel='stylesheet' href='../css/thickbox.css' type='text/css' media='screen' />
        <META HTTP-EQUIV="refresh" CONTENT="300">
        <script type="text/javascript">
            function llamaModal(rq){
                var url = 'pruebas.php?height=200&width=329&modal=true&id=';
                $("#enlaceModal").attr("href", url + rq);
                $("#enlaceModal").trigger("click");
            }
            function prueba(){
                alert("llego");
            }
        </script>
    <?php
        ## call of this method between HTML <HEAD> elements
        $dgrid->WriteCssClass();
    ?>
</head>
<body>
        <div style="display: none" >
            <a href='' class='thickbox' id="enlaceModal">Ventana</a>
           <!-- <input alt='prueba.php?height=90&width=320&inlineId=modalTexto&modal=true' class='thickbox' type='button' id='btnModal' value='Show' /> -->
        </div>
<?php
      $dgrid->Bind();
      ob_end_flush();
?>


</body>
</html>